{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ccc1aad",
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.stats.mstats import winsorize\n",
    "from scipy.stats import pearsonr,spearmanr,kendalltau\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "from gm.api import *\n",
    "set_token(\"eea4b28a3ceb7048603d388bb777ebc67de47385\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1004b0c9",
   "metadata": {},
   "source": [
    "# 股票估值\n",
    "\n",
    "参考链接：\n",
    "https://wenku.baidu.com/view/9baa6c79ac51f01dc281e53a580216fc710a533d.html?fr=income1-wk_app_search_ctr-search\n",
    "\n",
    "\n",
    "## 比率估值法\n",
    "\n",
    "* 比率估值法的基本理论\n",
    "\n",
    "现金流贴现估值法等内在价值法在计算上非常繁琐，而且不确定性因素很多，尤其是难以在不同的公司之间进行比较.而比率估值法通过寻找确定可比较资产，根据某个共同的变量，如收入、现金流量、账面价值或者销售收入,借助可比较资产的价值来估计标的资产的价值.在比率估值法中，资产的价值通过参考“可比”资产的价值与某一变量，如收益、现金流、账面价值或收入等比率而得到。比率估值法的优点在于简单且易于使用,应用该方法可以迅速获得被估价资产的价值。当金融市场上有大量可比资产进行交易，并且市场在平均水平上对这些资产的定价是正确的时候，应用比率估值法就比较适当。\n",
    "\n",
    "* 市盈率(PE)估值法\n",
    "\n",
    "市盈率(PE)是一个反映股票收益与风险的重要指标，也叫市价盈利率。它是用当前每股市场价格除以该公司的每股税后利润,其计算公式如下:\n",
    "市盈率=股票市价/每股税后利润\n",
    "市场广泛谈及的市盈率通常指的是静态市盈率，即以目前市场价格除以已知的最近公开的每股收益后的比值。但是静态市盈率只静态地考虑了当前的公司每股收益，没有动态地考虑公司的成长性，动态市盈率也就由此而生。动态市盈率计算公式如下：\n",
    "动态市盈率=静态市盈率×动态系数；动态系数=1/[(1+i）n]；其中i=企业每股收益的增长性比率，n=企业的可持续发展的存续期.\n",
    "\n",
    "* 市净率（PB）估值法\n",
    "\n",
    "市净率估值法的基本理论与市盈率(PE）估值法的基本理论相似，只是选用的财务比率不同，市净率指的是市价与每股净资产之间的比值，比值越低意味着风险越低。其计算公式如下 :市净率=股票市价/每股净资产。\n",
    "净资产的多少是由公司经营状况决定的，经营业绩越好，其资产增值越快,股票净值就越高，因此股东所拥有的权益也越多。\n",
    "\n",
    "* 比率估值法的适用性\n",
    "\n",
    "净资产、收益等数据容易获得且计算简单，并且对于那些不会使用现金流贴现估值方法的投资者而言，提供了一个非常简单的比较标准。投资者可以通过比较同行业中不同公司的市盈率、市净率来发现价值被高估或低估的企业。\n",
    "但在认识比率估值法时，至少要注意以下问题。第一,但是如果公司收益或获净资产是负值，比率估值法就失去了估值的意义;第二，如果市场高估或低估了某行业所有公司的价值，则运用这些公司的平均市盈率对某家该行业的公司进行估值，就会导致其股票价值的高估或低估。\n",
    "\n",
    "\n",
    "### classwork 1.2\n",
    "\n",
    "* 获取酒类板块与汽车板块各个股票的市盈率与市净率，并比较贵州茅台与比亚迪汽车\n",
    "\n",
    "* 计算这两个板块的平均市盈率与平均市净率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "f14522c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PELFY   -17.5180\n",
       "PB        2.5298\n",
       "dtype: float64"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sym=get_industry(code='C36')\n",
    "LFY_che=get_fundamentals_n(table='trading_derivative_indicator', symbols=sym, end_date=\"2022-05-01\", count=1,\n",
    "                            fields='PELFY,PB',df=True)\n",
    "LFY_che[[\"PELFY\",\"PB\"]].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "f12b1a74",
   "metadata": {},
   "outputs": [],
   "source": [
    "sym=get_constituents(index='SHSE.000941', fields='symbol, weight', df=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "344df200",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PELFY    35.4380\n",
       "PB        5.3496\n",
       "dtype: float64"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LFY_che=get_fundamentals_n(table='trading_derivative_indicator', symbols=sym.symbol.tolist(), end_date=\"2022-05-01\", count=1,\n",
    "                            fields='PELFY,PB',df=True)\n",
    "LFY_che[[\"PELFY\",\"PB\"]].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46b64e44",
   "metadata": {},
   "outputs": [],
   "source": [
    "LFY_jiu[LFY_jiu.symbol==]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "f6e39c4b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['SHSE.600059',\n",
       " 'SHSE.600084',\n",
       " 'SHSE.600132',\n",
       " 'SHSE.600189',\n",
       " 'SHSE.600197',\n",
       " 'SHSE.600199',\n",
       " 'SHSE.600238',\n",
       " 'SHSE.600300',\n",
       " 'SHSE.600365',\n",
       " 'SHSE.600519',\n",
       " 'SHSE.600559',\n",
       " 'SHSE.600600',\n",
       " 'SHSE.600616',\n",
       " 'SHSE.600696',\n",
       " 'SHSE.600702',\n",
       " 'SHSE.600543',\n",
       " 'SHSE.600573',\n",
       " 'SHSE.600779',\n",
       " 'SHSE.600809',\n",
       " 'SHSE.600962',\n",
       " 'SZSE.000568',\n",
       " 'SZSE.000596',\n",
       " 'SZSE.000729',\n",
       " 'SZSE.000752',\n",
       " 'SZSE.000799',\n",
       " 'SZSE.000848',\n",
       " 'SZSE.000858',\n",
       " 'SZSE.000860',\n",
       " 'SZSE.000869',\n",
       " 'SZSE.000929',\n",
       " 'SZSE.000995',\n",
       " 'SZSE.200596',\n",
       " 'SZSE.200869',\n",
       " 'SZSE.002304',\n",
       " 'SZSE.002461',\n",
       " 'SZSE.002525',\n",
       " 'SZSE.002568',\n",
       " 'SZSE.002646',\n",
       " 'SHSE.603369',\n",
       " 'SHSE.601579',\n",
       " 'SHSE.603198',\n",
       " 'SHSE.603589',\n",
       " 'SHSE.603919',\n",
       " 'SHSE.603779',\n",
       " 'SHSE.603711',\n",
       " 'SHSE.603156',\n",
       " 'SHSE.605388',\n",
       " 'SHSE.605388',\n",
       " 'SHSE.605198',\n",
       " 'SHSE.605198',\n",
       " 'SHSE.605337',\n",
       " 'SHSE.605337',\n",
       " 'SHSE.605499',\n",
       " 'SZSE.300997',\n",
       " 'SHSE.605499',\n",
       " 'SZSE.300997']"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sym=get_industry(code='C15')\n",
    "sym"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "88350c82",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>symbol</th>\n",
       "      <th>pub_date</th>\n",
       "      <th>end_date</th>\n",
       "      <th>PELFY</th>\n",
       "      <th>PB</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>SHSE.600059</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>42.1963</td>\n",
       "      <td>1.5578</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SHSE.600084</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>327.7130</td>\n",
       "      <td>2.5671</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>SHSE.600132</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>52.0596</td>\n",
       "      <td>28.9659</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>SHSE.600189</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>50.9600</td>\n",
       "      <td>2.6965</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>SHSE.600197</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>37.1217</td>\n",
       "      <td>3.0556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>SHSE.600199</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>246.2256</td>\n",
       "      <td>6.2011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>SHSE.600238</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>-91.8893</td>\n",
       "      <td>10.6324</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>SHSE.600300</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>25.7571</td>\n",
       "      <td>1.8975</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>SHSE.600365</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>443.0908</td>\n",
       "      <td>4.6214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>SHSE.600519</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>43.7819</td>\n",
       "      <td>11.1073</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>SHSE.600559</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>49.5898</td>\n",
       "      <td>4.8376</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>SHSE.600600</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>37.3144</td>\n",
       "      <td>4.8738</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>SHSE.600616</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>-299.9790</td>\n",
       "      <td>2.0034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>SHSE.600696</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>141.2342</td>\n",
       "      <td>17.7505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>SHSE.600702</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>39.1878</td>\n",
       "      <td>9.1616</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>SHSE.600543</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>-17.3744</td>\n",
       "      <td>1.6114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>SHSE.600573</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>71.6201</td>\n",
       "      <td>1.8840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>SHSE.600779</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>28.8480</td>\n",
       "      <td>11.7212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>SHSE.600809</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>62.4568</td>\n",
       "      <td>17.5190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>SHSE.600962</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>-110.9589</td>\n",
       "      <td>3.1663</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>SZSE.000568</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>38.9807</td>\n",
       "      <td>10.0160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>SZSE.000596</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>55.7252</td>\n",
       "      <td>6.3747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>SZSE.000729</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>84.7993</td>\n",
       "      <td>1.4419</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>SZSE.000752</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>-62.2098</td>\n",
       "      <td>32.9621</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>SZSE.000799</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>54.4804</td>\n",
       "      <td>12.0336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>SZSE.000848</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>15.6878</td>\n",
       "      <td>3.4469</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>SZSE.000858</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>26.9206</td>\n",
       "      <td>5.7268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>SZSE.000860</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>149.1480</td>\n",
       "      <td>1.9378</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>SZSE.000869</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>36.3221</td>\n",
       "      <td>1.7386</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>SZSE.000929</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>69.9759</td>\n",
       "      <td>2.0047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>SZSE.000995</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>-186.7692</td>\n",
       "      <td>20.1875</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>SZSE.200596</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>25.1874</td>\n",
       "      <td>2.8813</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>SZSE.200869</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>12.9932</td>\n",
       "      <td>0.6219</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>SZSE.002304</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>31.9275</td>\n",
       "      <td>5.0460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>SZSE.002461</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>27.8481</td>\n",
       "      <td>1.8198</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>SZSE.002568</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>35.2481</td>\n",
       "      <td>6.0376</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>SZSE.002646</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>130.5766</td>\n",
       "      <td>2.9221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>SHSE.603369</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>27.7469</td>\n",
       "      <td>6.0559</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>SHSE.601579</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>22.5074</td>\n",
       "      <td>1.7227</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>SHSE.603198</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>33.4640</td>\n",
       "      <td>7.0992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>SHSE.603589</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>17.7976</td>\n",
       "      <td>3.5191</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>SHSE.603919</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>46.5031</td>\n",
       "      <td>4.8017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>SHSE.603779</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>-4.9185</td>\n",
       "      <td>2.8759</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>SHSE.603711</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>14.7810</td>\n",
       "      <td>1.9032</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>SHSE.603156</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>13.8011</td>\n",
       "      <td>2.2486</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>SHSE.605388</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>42.7988</td>\n",
       "      <td>3.2139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>SHSE.605388</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>42.7988</td>\n",
       "      <td>3.2139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>SHSE.605198</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>34.7831</td>\n",
       "      <td>2.5011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>SHSE.605198</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>34.7831</td>\n",
       "      <td>2.5011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>SHSE.605337</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>25.8171</td>\n",
       "      <td>4.1166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>SHSE.605337</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>25.8171</td>\n",
       "      <td>4.1166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>SHSE.605499</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>41.4442</td>\n",
       "      <td>11.6658</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>SZSE.300997</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>27.9799</td>\n",
       "      <td>4.0234</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>SHSE.605499</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>41.4442</td>\n",
       "      <td>11.6658</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>SZSE.300997</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>27.9799</td>\n",
       "      <td>4.0234</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         symbol                  pub_date                  end_date     PELFY  \\\n",
       "0   SHSE.600059 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   42.1963   \n",
       "1   SHSE.600084 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00  327.7130   \n",
       "2   SHSE.600132 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   52.0596   \n",
       "3   SHSE.600189 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   50.9600   \n",
       "4   SHSE.600197 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   37.1217   \n",
       "5   SHSE.600199 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00  246.2256   \n",
       "6   SHSE.600238 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00  -91.8893   \n",
       "7   SHSE.600300 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   25.7571   \n",
       "8   SHSE.600365 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00  443.0908   \n",
       "9   SHSE.600519 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   43.7819   \n",
       "10  SHSE.600559 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   49.5898   \n",
       "11  SHSE.600600 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   37.3144   \n",
       "12  SHSE.600616 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00 -299.9790   \n",
       "13  SHSE.600696 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00  141.2342   \n",
       "14  SHSE.600702 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   39.1878   \n",
       "15  SHSE.600543 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00  -17.3744   \n",
       "16  SHSE.600573 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   71.6201   \n",
       "17  SHSE.600779 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   28.8480   \n",
       "18  SHSE.600809 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   62.4568   \n",
       "19  SHSE.600962 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00 -110.9589   \n",
       "20  SZSE.000568 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   38.9807   \n",
       "21  SZSE.000596 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   55.7252   \n",
       "22  SZSE.000729 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   84.7993   \n",
       "23  SZSE.000752 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00  -62.2098   \n",
       "24  SZSE.000799 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   54.4804   \n",
       "25  SZSE.000848 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   15.6878   \n",
       "26  SZSE.000858 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   26.9206   \n",
       "27  SZSE.000860 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00  149.1480   \n",
       "28  SZSE.000869 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   36.3221   \n",
       "29  SZSE.000929 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   69.9759   \n",
       "30  SZSE.000995 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00 -186.7692   \n",
       "31  SZSE.200596 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   25.1874   \n",
       "32  SZSE.200869 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   12.9932   \n",
       "33  SZSE.002304 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   31.9275   \n",
       "34  SZSE.002461 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   27.8481   \n",
       "35  SZSE.002568 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   35.2481   \n",
       "36  SZSE.002646 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00  130.5766   \n",
       "37  SHSE.603369 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   27.7469   \n",
       "38  SHSE.601579 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   22.5074   \n",
       "39  SHSE.603198 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   33.4640   \n",
       "40  SHSE.603589 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   17.7976   \n",
       "41  SHSE.603919 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   46.5031   \n",
       "42  SHSE.603779 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   -4.9185   \n",
       "43  SHSE.603711 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   14.7810   \n",
       "44  SHSE.603156 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   13.8011   \n",
       "45  SHSE.605388 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   42.7988   \n",
       "46  SHSE.605388 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   42.7988   \n",
       "47  SHSE.605198 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   34.7831   \n",
       "48  SHSE.605198 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   34.7831   \n",
       "49  SHSE.605337 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   25.8171   \n",
       "50  SHSE.605337 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   25.8171   \n",
       "51  SHSE.605499 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   41.4442   \n",
       "52  SZSE.300997 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   27.9799   \n",
       "53  SHSE.605499 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   41.4442   \n",
       "54  SZSE.300997 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00   27.9799   \n",
       "\n",
       "         PB  \n",
       "0    1.5578  \n",
       "1    2.5671  \n",
       "2   28.9659  \n",
       "3    2.6965  \n",
       "4    3.0556  \n",
       "5    6.2011  \n",
       "6   10.6324  \n",
       "7    1.8975  \n",
       "8    4.6214  \n",
       "9   11.1073  \n",
       "10   4.8376  \n",
       "11   4.8738  \n",
       "12   2.0034  \n",
       "13  17.7505  \n",
       "14   9.1616  \n",
       "15   1.6114  \n",
       "16   1.8840  \n",
       "17  11.7212  \n",
       "18  17.5190  \n",
       "19   3.1663  \n",
       "20  10.0160  \n",
       "21   6.3747  \n",
       "22   1.4419  \n",
       "23  32.9621  \n",
       "24  12.0336  \n",
       "25   3.4469  \n",
       "26   5.7268  \n",
       "27   1.9378  \n",
       "28   1.7386  \n",
       "29   2.0047  \n",
       "30  20.1875  \n",
       "31   2.8813  \n",
       "32   0.6219  \n",
       "33   5.0460  \n",
       "34   1.8198  \n",
       "35   6.0376  \n",
       "36   2.9221  \n",
       "37   6.0559  \n",
       "38   1.7227  \n",
       "39   7.0992  \n",
       "40   3.5191  \n",
       "41   4.8017  \n",
       "42   2.8759  \n",
       "43   1.9032  \n",
       "44   2.2486  \n",
       "45   3.2139  \n",
       "46   3.2139  \n",
       "47   2.5011  \n",
       "48   2.5011  \n",
       "49   4.1166  \n",
       "50   4.1166  \n",
       "51  11.6658  \n",
       "52   4.0234  \n",
       "53  11.6658  \n",
       "54   4.0234  "
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LFY_jiu=get_fundamentals_n(table='trading_derivative_indicator', symbols=sym, end_date=\"2022-05-01\", count=1,\n",
    "                            fields='PELFY,PB',df=True)\n",
    "LFY_jiu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "2834dbbb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PELFY    40.7841\n",
       "PB        6.2963\n",
       "dtype: float64"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LFY_jiu[[\"PELFY\",\"PB\"]].mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1076724",
   "metadata": {},
   "source": [
    "动态市盈率=静态市盈率x动态系数\n",
    "动态市盈率，其计算公式是以静态市盈率为基数，乘以动态系数，该系数为1/(1+i)^n，i为企业每股收益的增长性比率，n为企业的可持续发展的存续期。比如说，上市公司当前股价为20元，每股收益为0.38元，上年同期每股收益为0.28元，成长性为35%，即i=35%，该企业未来保持该增长速度的时间可持续5年，即n=5；则动态系数为1/(1+35%)^5=22%。相应地，动态市盈率为11.44倍，即：52（静态市盈率：20元/0.38元=52)×22%。两者相比，相差之大，相信普通投资人看了会大吃一惊，恍然大悟。动态市盈率理论告诉我们一个简单朴素而又深刻的道理，即投资股市一定要选择有持续成长性的公司。于是，我们不难理解资产重组为什么会成为市场永恒的主题，及有些业绩不好的公司在实质性的重组题材支撑下成为市场黑马。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2b7f641b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "52.63157894736842"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "20/0.38"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3370cff0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.22301350200402015"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1/(1+0.35)**5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5fb200a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11.44"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "52*0.22"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f20239c9",
   "metadata": {},
   "source": [
    "## classwork 1.1\n",
    "\n",
    "* 求SZSE.300750宁德时代最近一期的动态市盈率\n",
    "\n",
    "表名: income_statement\n",
    "\n",
    "NETPROFIT\t净利润\t元"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "a9071f2d",
   "metadata": {},
   "outputs": [],
   "source": [
    "LFY_nd=get_fundamentals_n(table='trading_derivative_indicator', symbols=\"SZSE.300750\", end_date=\"2022-05-01\", count=2,\n",
    "                            fields='PELFY',df=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "5671f12a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>symbol</th>\n",
       "      <th>pub_date</th>\n",
       "      <th>end_date</th>\n",
       "      <th>PELFY</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>2022-04-29 00:00:00+08:00</td>\n",
       "      <td>59.8905</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2022-04-28 00:00:00+08:00</td>\n",
       "      <td>2022-04-28 00:00:00+08:00</td>\n",
       "      <td>56.6937</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        symbol                  pub_date                  end_date    PELFY\n",
       "0  SZSE.300750 2022-04-29 00:00:00+08:00 2022-04-29 00:00:00+08:00  59.8905\n",
       "1  SZSE.300750 2022-04-28 00:00:00+08:00 2022-04-28 00:00:00+08:00  56.6937"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LFY_nd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "8148903e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>symbol</th>\n",
       "      <th>pub_date</th>\n",
       "      <th>end_date</th>\n",
       "      <th>NETPROFIT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2022-04-30 00:00:00+08:00</td>\n",
       "      <td>2022-03-31 00:00:00+08:00</td>\n",
       "      <td>1.9755e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2022-04-22 00:00:00+08:00</td>\n",
       "      <td>2021-12-31 00:00:00+08:00</td>\n",
       "      <td>1.7861e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2021-10-28 00:00:00+08:00</td>\n",
       "      <td>2021-09-30 00:00:00+08:00</td>\n",
       "      <td>9.1450e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2021-08-26 00:00:00+08:00</td>\n",
       "      <td>2021-06-30 00:00:00+08:00</td>\n",
       "      <td>5.3251e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2021-04-30 00:00:00+08:00</td>\n",
       "      <td>2021-03-31 00:00:00+08:00</td>\n",
       "      <td>2.3439e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2021-04-28 00:00:00+08:00</td>\n",
       "      <td>2020-12-31 00:00:00+08:00</td>\n",
       "      <td>6.1039e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2020-10-28 00:00:00+08:00</td>\n",
       "      <td>2020-09-30 00:00:00+08:00</td>\n",
       "      <td>3.6822e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2020-08-27 00:00:00+08:00</td>\n",
       "      <td>2020-06-30 00:00:00+08:00</td>\n",
       "      <td>2.1439e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2020-04-28 00:00:00+08:00</td>\n",
       "      <td>2020-03-31 00:00:00+08:00</td>\n",
       "      <td>9.0501e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2020-04-25 00:00:00+08:00</td>\n",
       "      <td>2019-12-31 00:00:00+08:00</td>\n",
       "      <td>5.0127e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2019-10-26 00:00:00+08:00</td>\n",
       "      <td>2019-09-30 00:00:00+08:00</td>\n",
       "      <td>3.7602e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2019-08-24 00:00:00+08:00</td>\n",
       "      <td>2019-06-30 00:00:00+08:00</td>\n",
       "      <td>2.3465e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2019-04-27 00:00:00+08:00</td>\n",
       "      <td>2019-03-31 00:00:00+08:00</td>\n",
       "      <td>1.1168e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2019-04-25 00:00:00+08:00</td>\n",
       "      <td>2018-12-31 00:00:00+08:00</td>\n",
       "      <td>3.7359e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>SZSE.300750</td>\n",
       "      <td>2018-10-26 00:00:00+08:00</td>\n",
       "      <td>2018-09-30 00:00:00+08:00</td>\n",
       "      <td>2.6422e+09</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         symbol                  pub_date                  end_date  \\\n",
       "0   SZSE.300750 2022-04-30 00:00:00+08:00 2022-03-31 00:00:00+08:00   \n",
       "1   SZSE.300750 2022-04-22 00:00:00+08:00 2021-12-31 00:00:00+08:00   \n",
       "2   SZSE.300750 2021-10-28 00:00:00+08:00 2021-09-30 00:00:00+08:00   \n",
       "3   SZSE.300750 2021-08-26 00:00:00+08:00 2021-06-30 00:00:00+08:00   \n",
       "4   SZSE.300750 2021-04-30 00:00:00+08:00 2021-03-31 00:00:00+08:00   \n",
       "5   SZSE.300750 2021-04-28 00:00:00+08:00 2020-12-31 00:00:00+08:00   \n",
       "6   SZSE.300750 2020-10-28 00:00:00+08:00 2020-09-30 00:00:00+08:00   \n",
       "7   SZSE.300750 2020-08-27 00:00:00+08:00 2020-06-30 00:00:00+08:00   \n",
       "8   SZSE.300750 2020-04-28 00:00:00+08:00 2020-03-31 00:00:00+08:00   \n",
       "9   SZSE.300750 2020-04-25 00:00:00+08:00 2019-12-31 00:00:00+08:00   \n",
       "10  SZSE.300750 2019-10-26 00:00:00+08:00 2019-09-30 00:00:00+08:00   \n",
       "11  SZSE.300750 2019-08-24 00:00:00+08:00 2019-06-30 00:00:00+08:00   \n",
       "12  SZSE.300750 2019-04-27 00:00:00+08:00 2019-03-31 00:00:00+08:00   \n",
       "13  SZSE.300750 2019-04-25 00:00:00+08:00 2018-12-31 00:00:00+08:00   \n",
       "14  SZSE.300750 2018-10-26 00:00:00+08:00 2018-09-30 00:00:00+08:00   \n",
       "\n",
       "     NETPROFIT  \n",
       "0   1.9755e+09  \n",
       "1   1.7861e+10  \n",
       "2   9.1450e+09  \n",
       "3   5.3251e+09  \n",
       "4   2.3439e+09  \n",
       "5   6.1039e+09  \n",
       "6   3.6822e+09  \n",
       "7   2.1439e+09  \n",
       "8   9.0501e+08  \n",
       "9   5.0127e+09  \n",
       "10  3.7602e+09  \n",
       "11  2.3465e+09  \n",
       "12  1.1168e+09  \n",
       "13  3.7359e+09  \n",
       "14  2.6422e+09  "
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cw_nd=get_fundamentals_n(table='income_statement', symbols=\"SZSE.300750\", end_date=\"2022-05-01\", count=15,\n",
    "                            fields='NETPROFIT',df=True)\n",
    "cw_nd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "a0c0cee0",
   "metadata": {},
   "outputs": [],
   "source": [
    "cw_nd.set_index(\"end_date\",inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "ad9dd593",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "end_date\n",
       "2022-03-31 00:00:00+08:00    2.3439e+09\n",
       "2021-12-31 00:00:00+08:00    6.1039e+09\n",
       "2021-09-30 00:00:00+08:00    3.6822e+09\n",
       "2021-06-30 00:00:00+08:00    2.1439e+09\n",
       "2021-03-31 00:00:00+08:00    9.0501e+08\n",
       "2020-12-31 00:00:00+08:00    5.0127e+09\n",
       "2020-09-30 00:00:00+08:00    3.7602e+09\n",
       "2020-06-30 00:00:00+08:00    2.3465e+09\n",
       "2020-03-31 00:00:00+08:00    1.1168e+09\n",
       "2019-12-31 00:00:00+08:00    3.7359e+09\n",
       "2019-09-30 00:00:00+08:00    2.6422e+09\n",
       "2019-06-30 00:00:00+08:00           NaN\n",
       "2019-03-31 00:00:00+08:00           NaN\n",
       "2018-12-31 00:00:00+08:00           NaN\n",
       "2018-09-30 00:00:00+08:00           NaN\n",
       "Name: NETPROFIT, dtype: float64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cw_nd.NETPROFIT.shift(-4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "e631655c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "end_date\n",
       "2022-03-31 00:00:00+08:00    1.9755e+09\n",
       "2021-12-31 00:00:00+08:00    1.7861e+10\n",
       "2021-09-30 00:00:00+08:00    9.1450e+09\n",
       "2021-06-30 00:00:00+08:00    5.3251e+09\n",
       "2021-03-31 00:00:00+08:00    2.3439e+09\n",
       "2020-12-31 00:00:00+08:00    6.1039e+09\n",
       "2020-09-30 00:00:00+08:00    3.6822e+09\n",
       "2020-06-30 00:00:00+08:00    2.1439e+09\n",
       "2020-03-31 00:00:00+08:00    9.0501e+08\n",
       "2019-12-31 00:00:00+08:00    5.0127e+09\n",
       "2019-09-30 00:00:00+08:00    3.7602e+09\n",
       "2019-06-30 00:00:00+08:00    2.3465e+09\n",
       "2019-03-31 00:00:00+08:00    1.1168e+09\n",
       "2018-12-31 00:00:00+08:00    3.7359e+09\n",
       "2018-09-30 00:00:00+08:00    2.6422e+09\n",
       "Name: NETPROFIT, dtype: float64"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cw_nd.NETPROFIT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "f32fe072",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "end_date\n",
       "2022-03-31 00:00:00+08:00   -0.1572\n",
       "2021-12-31 00:00:00+08:00    1.9261\n",
       "2021-09-30 00:00:00+08:00    1.4836\n",
       "2021-06-30 00:00:00+08:00    1.4838\n",
       "2021-03-31 00:00:00+08:00    1.5899\n",
       "2020-12-31 00:00:00+08:00    0.2177\n",
       "2020-09-30 00:00:00+08:00   -0.0207\n",
       "2020-06-30 00:00:00+08:00   -0.0863\n",
       "2020-03-31 00:00:00+08:00   -0.1897\n",
       "2019-12-31 00:00:00+08:00    0.3418\n",
       "2019-09-30 00:00:00+08:00    0.4231\n",
       "2019-06-30 00:00:00+08:00       NaN\n",
       "2019-03-31 00:00:00+08:00       NaN\n",
       "2018-12-31 00:00:00+08:00       NaN\n",
       "2018-09-30 00:00:00+08:00       NaN\n",
       "Name: NETPROFIT, dtype: float64"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(cw_nd.NETPROFIT/cw_nd.NETPROFIT.shift(-4)-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "ba17aede",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6374567896311606"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(cw_nd.NETPROFIT/cw_nd.NETPROFIT.shift(-4)-1).mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "8c7fcbe8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='end_date'>"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAESCAYAAAAWtRmOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAybElEQVR4nO3deXhU5fXA8e/JSiZAmLBLBgKCLLIJAUF2rYhWi1oqUPeqqBWX1r2bVru570r5KcVq1WoVN2QrKCqoJCC7BAJEEnbIBoGQ7f39kTt0TDLJJJmZOzM5n+eZh+TeO3dOLsrJux4xxqCU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NS1TRkS2kRmSsiU+q55hoROaXpkSkVPJoclAq8awBNDiqsaHJQEUlErhCRVSKyVkT+LiLRVgGmP4vIOhH5WkQ6Wtd2F5GvRCRdRB6u574iIs+LyGYRmY/Hjpgi8gfrHhtFZLZ17RSqVmb/y4olQaqKDi23CrIscu+To1Qo0eSgIo6I9AWmAqOMMYOBCuByqgoxfW2MGQR8DtxgveUZ4CVjzDBgXz23vwToDQyw3n+Wx7nnjTHDjDH9gQTgQmPMf4AM4HIrlnLgOWCKMWYoMAf4c9N+YqX8T7fsVpHoHGAokG5tb5xA1c6VpcDH1jWrqSqcAjCKqv3vAV6jartjb8YCbxpjKoA9IrLM49wEEbmHqspbycAm4KNq7+9NVZWuJVZs0cDeBv58SgWcJgcViQR41Rhz/w8Oitxl/reZWAU//O+/IZuM1bhWRFoALwJpxpgcEXkQaOEltk2matt2pUKWdiupSLQUmOKxRXqyiHSr4/oVwDTr68vruffnwDRrDKMzMME67k4Eh6ziLJ4zmI5QVQMYqup4tBeRkVZssVZxFqVCiiYHFXGMMZup2r54sYisB5ZQVWvXm9uBW0Qknao97+syj6qtkjcALwHLrc8sAP7POv4+kO7xnrnALBFZS1U30hTgERFZR9X2yZ7jFkqFBN2yWymlVA3aclBKKVWDDkgrVQsRGUDVzCVPJ4wxZ9oRj1LBpt1KSimlatBuJaWUUjVoclBKKVWDJgellFI1aHJQSilVw/8DI42iPquFnLgAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "cw_nd.NETPROFIT.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "6531688d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9.044312641831365"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "56*(1/(1+0.2)**10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c455979e",
   "metadata": {},
   "source": [
    "# 自由现金流估值法 DCF\n",
    "\n",
    "参考链接：\n",
    "\n",
    "DCF方法的理解：\n",
    "\n",
    "https://zhuanlan.zhihu.com/p/358808637\n",
    "\n",
    "https://zhuanlan.zhihu.com/p/370721850\n",
    "\n",
    "https://xueqiu.com/1457764636/164180774?ivk_sa=1024320u\n",
    "\n",
    "DCF的python实现：\n",
    "\n",
    "https://blog.csdn.net/wuditong321/article/details/121158754\n",
    "\n",
    "https://github.com/xuelixunhua/stock_DCF\n",
    "\n",
    "\n",
    "* 现金流贴现估值法\n",
    "\n",
    "自由现金流贴现估值法是最为广泛认同和接受的主流价值估值法。这一模型在资本市场发达的国家中被广泛应用于投资分析和投资组合管理、公司并购和公司财务等领域。\n",
    "\n",
    "* 现金流贴现估值法的基本原理\n",
    "\n",
    "任何资产的价值等于其预期未来全部现金流的现值总和，这是现金流贴现估值方法的估值原理。即通过选取适当的贴现率，折算出预期在公司生命周期内可能产生全部的现金流之和，从而得出公司的价值.现金流会因所估资产的不同而有差异.对股票来说,现金流是红利；对债券而言，现金流是利息和本金；对实际项目而言，现金流是税后净现金流。贴现率取决于所预测现金流的风险程度，资产风险越高，贴现率就越高；反之,资产风险越低，贴现率越低。\n",
    "\n",
    "有以下四种模型：\n",
    "\n",
    "1. 零增长模型\n",
    "2. 不变增长模型\n",
    "3. 两阶段模型\n",
    "4. 三阶段模型\n",
    "\n",
    "不同的是自由现金流的使用和贴现的方式不同。\n",
    "\n",
    "**计算步骤**：\n",
    "\n",
    "1. 计算自由现金流并依据相应的方法折现($\\star\\star\\star\\star\\star$, the most important, this is what the code solves)\n",
    "2. 计算股权价值= 1.+金融资产+长期股权投资-公司债务\n",
    "3. 计算少数股东比例\n",
    "4. 归属于上市公司股东的价值=股权价值$\\times$(1-少数股东比例)\n",
    "5. 每股内在价值=归属于上市公司股东的价值/股本\n",
    "\n",
    "其中，\n",
    "\n",
    "- 经营资产自由现金流=公司维持原有生产经营规模前提下的增量现金流入=经营活动现金流量净额-保全性资本支出=经营活动现金流量净额-固定资产折旧-无形资产和长期待摊费用摊销-处置长期资产的损失\n",
    "- $WACC=k_d\\times\\frac{D}{D+E}\\times(1-t)+k_e\\times\\frac{E}{D+E}$。其中债务资本成本率=债务资本总额/债务资本平均金额$\\times$100%=(财务费用+汇兑收益)/(期初债务资本+期末债务资本)/2；股权资本成本率应该高于同期的国债利率，加上股票投资的风险溢价，我们普遍设置为8%；t为公司实际所得税税率=1-净利润/税前利润。\n",
    "- 公司债务=有息债务\n",
    "- 少数股东比例=$\\frac{少数股东权益}{股东权益合计}$\n",
    "- 股本=市值/股价\n",
    "\n",
    "\n",
    "$$\n",
    "\\begin{aligned}\n",
    "&零增长模型：V=\\frac{FCF}{WACC}\\\\\n",
    "&不变增长模型：V=\\frac{FCF(1+g)}{WACC-g}\\\\\n",
    "&两阶段模型：V=\\sum_{t=1}^n\\frac{{FCF}_t}{(1+WACC)^t}+\\frac{TV}{(1+WACC)^n}，\\ \\  其中TV=\\frac{FCF_n(1+g_2)}{WACC-g_2}\\\\\n",
    "&三阶段模型：V=\\sum_{t=1}^n\\frac{{FCF}_0(1+g_1)}{(1+WACC)^t}+\\sum_{t=n+1}^m\\frac{{FCF}_n(1+g_2)}{(1+WACC)^t}+\\frac{FCF_{n+m}(1+g_3)}{(WACC-g_3)(1+WACC)^{n+m}}\\\\\n",
    "\\end{aligned}\n",
    "$$\n",
    "\n",
    "零增长模型适用于成熟稳定、没有增长的公司，每年的自由现金流也保持在一个稳定的金额水平，类似于永续年金；如果该类公司的自由现金流全部用于发放股利现金，那么其得出的结果与股利贴现模型非常接近。\n",
    "\n",
    "不变增长模型适用于成熟的公司，未来的自由现金流以非常缓慢的速度增长。\n",
    "\n",
    "在两阶段模型中，投资者的预期回报WACC至少要高于总体的经济增长率；不变增长率g2通常小于WACC，反之，意味着很长时间以后公司的规模将超过总体经济规模。\n",
    "\n",
    "在三阶段模型中，假设所有的公司经历三个阶段：成长阶段、过渡阶段和稳定阶段。三个阶段的成长率由高到低，稳定阶段保持较低增长率的不变增长。\n",
    "\n",
    "\n",
    "### classwork 1.2\n",
    "\n",
    "* 参考上述例子，实现基于掘金平台，股票sz000977最近一期的DCF计算。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "abfef332",
   "metadata": {},
   "source": [
    "### classwork1.3\n",
    "\n",
    "* 参考https://zhuanlan.zhihu.com/p/358808637  计算茅台的估值\n",
    "\n",
    "表名: deriv_finance_indicator\n",
    "\n",
    "FCFF\t企业自由现金流量\t元\t利润总额＋利息支出＋固定资产折旧＋无形资产摊销＋长期待摊费用摊销 － 所得税 － 资本性支出 － 营运资本净增加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "154fc051",
   "metadata": {},
   "outputs": [],
   "source": [
    "cw_mt=get_fundamentals_n(table='deriv_finance_indicator', symbols=\"SHSE.600519\", end_date=\"2022-05-01\", count=50,\n",
    "                            fields='FCFF',df=True)\n",
    "cw_mt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50779c62",
   "metadata": {},
   "outputs": [],
   "source": [
    "cw_mt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4e4f060",
   "metadata": {},
   "source": [
    "我们简单的用两阶段增长模型来计算一下A股股王贵州茅台的估值，茅台最新发布的20年扣非净利润是455亿，我们直接用这个数字作为D0，第一个阶段为10年，增长率为g1=15% ，第二个阶段即第11年开始的永续增长率为8%，我们期望的年化收益率为r=12%，则可以通过上述方法计算出茅台当前市值为20,835亿元，对应的股价大概为1662元。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "a42ce9ba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "467.18749999999994\n",
      "479.70145089285705\n",
      "492.55059689891556\n",
      "505.7439164587079\n",
      "519.2906285067089\n",
      "533.2001989131385\n",
      "547.4823470983117\n",
      "562.1470528241593\n",
      "577.2045631676634\n",
      "592.6653996810828\n"
     ]
    }
   ],
   "source": [
    "t=0\n",
    "for i in range(1,11):\n",
    "    t=t+455*(1+0.15)**i/(1+0.12)**i\n",
    "    print(455*(1+0.15)**i/(1+0.12)**i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "a4ee8990",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16011.000000000004"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(593*(1+0.08)/(0.12-0.08))/(1+0.12)**10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "98f6e4ee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10423.173654441545"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t+5146"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c9d8a5b",
   "metadata": {},
   "source": [
    "现金流量表\n",
    "\n",
    "表名: cashflow_statement\n",
    "FINEXPE\t财务费用\t元\n",
    "\n",
    "利润表\n",
    "\n",
    "表名: income_statement\n",
    "EXCHGGAIN\t汇兑收益\t元\n",
    "\n",
    "衍生财务指标\n",
    "\n",
    "表名: deriv_finance_indicator\n",
    "ASSLIABRT\t资产负债率\t%\t负债总额/资产总额＊100%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "821c1b27",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
